<template>
    <div>文件上传</div>
     
    <el-upload
    class="avatar-uploader"
    action="http://localhost:8082/lxhotel/uploadServlet.do"
    :show-file-list="false"
    :on-success="handleAvatarSuccess"
    :before-upload="beforeAvatarUpload"
  >
    <img v-if="imageUrl" :src="imageUrl" class="avatar" />
    <el-icon v-else class="avatar-uploader-icon"><Plus /></el-icon>
  </el-upload>





    <div style="font-size: 20px">
    <!-- 由于SVG图标默认不携带任何属性 -->
    <!-- 你需要直接提供它们 -->
    <Edit style="width: 1em; height: 1em; margin-right: 8px" />
    <Share style="width: 1em; height: 1em; margin-right: 8px" />
    <Delete style="width: 1em; height: 1em; margin-right: 8px" />
    <Search style="width: 1em; height: 1em; margin-right: 8px" />
  </div>
  

</template>

<script>
import { ref } from 'vue'
import { ElMessage } from 'element-plus'

export default{
    name:'Upload',
    setup(){
        let imageUrl = ref('')   ;
        //图片上传成功后的回调函数  ，resp 后端响应的数据对象
        function handleAvatarSuccess(resp,uploadFile){
            console.log("文件上传成功，回调",resp);
            if(resp.code ==0){
              imageUrl.value =  resp.dataparam.imgUrl ;
              console.log('imageUrl',imageUrl);
            }
        }

        //图片上传前的回调函数
        function beforeAvatarUpload(){
          console.log("文件开始上传，回调");
        }
        return{
            imageUrl,
            handleAvatarSuccess,
            beforeAvatarUpload
        }
    }
}
</script>

<style scoped>
.avatar-uploader .avatar {
  width: 178px;
  height: 178px;
  display: block;
}
</style>


<style>

.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}


.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  text-align: center;
}


</style>

